# Generated by Django 4.2.1 on 2023-08-08 22:49

from django.conf import settings
import django.contrib.postgres.fields
from django.db import connection, migrations, models
import django.db.models.deletion
import uuid

from llmstack.common.utils.db_models import ArrayField


class Migration(migrations.Migration):

    if connection.vendor == 'postgresql':
        accessible_by_field = (
            'accessible_by',
            django.contrib.postgres.fields.ArrayField(
                base_field=models.CharField(
                    max_length=320),
                blank=True,
                default=list,
                help_text='List of user emails or domains who can access the app',
                size=None,
            ))
    else:
        accessible_by_field = ('accessible_by', ArrayField(
            null=True,
            help_text='List of user emails or domains who can access the app',
            blank=True,
        ))

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
        ('apiabstractor', '0001_initial'),
    ]

    operations = [
        migrations.CreateModel(
            name='App',
            fields=[
                ('id', models.BigAutoField(auto_created=True,
                 primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(help_text='Name of the app', max_length=100)),
                ('published_uuid', models.UUIDField(blank=True, default=uuid.uuid4,
                 help_text='Identifier for the app when published', null=True, unique=True)),
                ('uuid', models.UUIDField(default=uuid.uuid4,
                 help_text='Identifier for the app')),
                ('config', models.JSONField(blank=True, default=dict,
                 help_text='Config for this app based on the app type')),
                ('input_schema', models.JSONField(blank=True, default=dict,
                 help_text='Input fields for this app in JSON schema format', null=True)),
                ('input_ui_schema', models.JSONField(blank=True, default=dict,
                 help_text='UI schema for input_schema', null=True)),
                ('output_template', models.JSONField(blank=True, default=dict,
                 help_text='Output template for this app in JSON format. We support markdown, JSON etc., as keys', null=True)),
                ('description', models.TextField(blank=True, default='',
                 help_text='Description of the app. Support markdown.')),
                ('data_transformer', models.TextField(blank=True, default='',
                 help_text='Data transformer to be applied before calling the first node of the run graph')),
                ('is_public', models.BooleanField(default=True,
                 help_text='Whether the app is public or not')),
                ('is_published', models.BooleanField(blank=True, default=False,
                 help_text='Whether the app is published or not')),
                ('is_cloneable', models.BooleanField(default=False,
                 help_text='Whether the app is cloneable or not')),
                ('domain', models.CharField(blank=True, default=None,
                 help_text='Custom domain associated with the app', max_length=2000, null=True)),
                ('visibility', models.PositiveSmallIntegerField(choices=[(0, 'Private'), (1, 'Organization'), (
                    2, 'Unlisted'), (3, 'Public')], default=3, help_text='Visibility of the app')),
                accessible_by_field,
                ('access_permission', models.PositiveSmallIntegerField(choices=[
                 (0, 'Read'), (1, 'Write')], default=0, help_text='Permission for users who can access the app')),
                ('created_at', models.DateTimeField(auto_now_add=True,
                 help_text='Time at which the app was created', null=True)),
                ('last_updated_at', models.DateTimeField(auto_now=True,
                 help_text='Time at which the app was last updated', null=True)),
                ('web_integration_config', models.JSONField(blank=True,
                 default=dict, help_text='Embed config for this app')),
                ('slack_integration_config', models.JSONField(blank=True,
                 default=dict, help_text='Slack config for this app')),
                ('discord_integration_config', models.JSONField(blank=True,
                 default=dict, help_text='Discord config for this app')),
                ('last_modified_by', models.ForeignKey(default=None, help_text='Last modified by', null=True,
                 on_delete=django.db.models.deletion.DO_NOTHING, related_name='last_modified_by', to=settings.AUTH_USER_MODEL)),
                ('owner', models.ForeignKey(help_text='Owner of the app',
                 on_delete=django.db.models.deletion.DO_NOTHING, to=settings.AUTH_USER_MODEL)),
            ],
        ),
        migrations.CreateModel(
            name='AppSession',
            fields=[
                ('id', models.BigAutoField(auto_created=True,
                 primary_key=True, serialize=False, verbose_name='ID')),
                ('uuid', models.UUIDField(
                    default=uuid.uuid4, help_text='UUID for the run')),
                ('created_at', models.DateTimeField(auto_now_add=True,
                 help_text='Time at which the app instance was created')),
                ('last_updated_at', models.DateTimeField(auto_now=True,
                 help_text='Time at which the app instance was last updated')),
                ('app', models.ForeignKey(help_text='App of the app instance',
                 on_delete=django.db.models.deletion.DO_NOTHING, to='apps.app')),
            ],
        ),
        migrations.CreateModel(
            name='AppTemplateCategory',
            fields=[
                ('id', models.BigAutoField(auto_created=True,
                 primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(
                    help_text='Name of the app template category', max_length=100)),
                ('description', models.TextField(blank=True, default='',
                 help_text='Description of the app template category')),
                ('slug', models.CharField(
                    default='', help_text='Slug of the app template category', max_length=100, unique=True)),
            ],
        ),
        migrations.CreateModel(
            name='AppType',
            fields=[
                ('id', models.BigAutoField(auto_created=True,
                 primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(
                    help_text='Name of the app type', max_length=100)),
                ('description', models.TextField(blank=True,
                 default='', help_text='Description of the app type')),
                ('slug', models.CharField(
                    default='', help_text='Slug of the app type', max_length=100, unique=True)),
            ],
        ),
        migrations.CreateModel(
            name='TestSet',
            fields=[
                ('id', models.BigAutoField(auto_created=True,
                 primary_key=True, serialize=False, verbose_name='ID')),
                ('uuid', models.UUIDField(default=uuid.uuid4,
                 help_text='UUID for the test set')),
                ('name', models.CharField(
                    help_text='Name of the app test set', max_length=100)),
                ('created_at', models.DateTimeField(auto_now_add=True,
                 help_text='Time at which the app instance was created')),
                ('last_updated_at', models.DateTimeField(auto_now=True,
                 help_text='Time at which the app instance was last updated')),
                ('app', models.ForeignKey(help_text='App of the test set',
                 on_delete=django.db.models.deletion.DO_NOTHING, to='apps.app')),
            ],
        ),
        migrations.CreateModel(
            name='TestCase',
            fields=[
                ('id', models.BigAutoField(auto_created=True,
                 primary_key=True, serialize=False, verbose_name='ID')),
                ('uuid', models.UUIDField(default=uuid.uuid4,
                 help_text='UUID for the test case')),
                ('input_data', models.JSONField(
                    default=dict, help_text='Test Case input data')),
                ('expected_output', models.TextField(default='',
                 help_text='Expected output for the test case')),
                ('created_at', models.DateTimeField(auto_now_add=True,
                 help_text='Time at which the app instance was created')),
                ('last_updated_at', models.DateTimeField(auto_now=True,
                 help_text='Time at which the app instance was last updated')),
                ('testset', models.ForeignKey(help_text='Test set',
                 on_delete=django.db.models.deletion.DO_NOTHING, to='apps.testset')),
            ],
        ),
        migrations.CreateModel(
            name='AppTemplate',
            fields=[
                ('id', models.BigAutoField(auto_created=True,
                 primary_key=True, serialize=False, verbose_name='ID')),
                ('name', models.CharField(
                    help_text='Name of the app template', max_length=100)),
                ('description', models.TextField(blank=True, default='',
                 help_text='Description of the app template')),
                ('slug', models.CharField(
                    default='', help_text='Slug of the app template', max_length=100, unique=True)),
                ('app_uuid', models.UUIDField(default=uuid.uuid4,
                 help_text='UUID of the app this template is based on. App is used to get the processor chain etc.,')),
                ('example_app_uuid', models.CharField(blank=True, default='',
                 help_text='UUID of the example app for this template', max_length=100)),
                ('order', models.IntegerField(default=0,
                 help_text='Order of the app template in the category')),
                ('categories', models.ManyToManyField(blank=True, default=None,
                 help_text='Categories of the app template', to='apps.apptemplatecategory')),
            ],
        ),
        migrations.CreateModel(
            name='AppSessionData',
            fields=[
                ('id', models.BigAutoField(auto_created=True,
                 primary_key=True, serialize=False, verbose_name='ID')),
                ('data', models.JSONField(blank=True, default=dict,
                 help_text='Data for this endpoint')),
                ('created_at', models.DateTimeField(auto_now_add=True,
                 help_text='Time at which the app instance was created')),
                ('last_updated_at', models.DateTimeField(auto_now=True,
                 help_text='Time at which the app instance was last updated')),
                ('app_session', models.ForeignKey(help_text='App session',
                 on_delete=django.db.models.deletion.DO_NOTHING, to='apps.appsession')),
                ('endpoint', models.ForeignKey(help_text='Endpoint',
                 on_delete=django.db.models.deletion.DO_NOTHING, to='apiabstractor.endpoint')),
            ],
        ),
        migrations.CreateModel(
            name='AppRunGraphEntry',
            fields=[
                ('id', models.BigAutoField(auto_created=True,
                 primary_key=True, serialize=False, verbose_name='ID')),
                ('logic_gate', models.TextField(blank=True, default='',
                 help_text='Logic gate to be applied on the edge specified as Jinja2 template over output schema of entry endpoint')),
                ('data_transformer', models.TextField(blank=True, default='',
                 help_text='Data transformer to be applied on the edge specified as Jinja2 template over output schema of entry endpoint and input of exit endpoint')),
                ('entry_endpoint', models.ForeignKey(blank=True, default=None, help_text='Start endpoint of the edge. Null for first entry',
                 null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='entry_endpoint', to='apiabstractor.endpoint')),
                ('exit_endpoint', models.ForeignKey(blank=True, default=None, help_text='End endpoint of the edge. Null for last entry',
                 null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='exit_endpoint', to='apiabstractor.endpoint')),
                ('owner', models.ForeignKey(default=None, help_text='Owner of the node', null=True,
                 on_delete=django.db.models.deletion.DO_NOTHING, to=settings.AUTH_USER_MODEL)),
            ],
        ),
        migrations.CreateModel(
            name='AppHub',
            fields=[
                ('id', models.BigAutoField(auto_created=True,
                 primary_key=True, serialize=False, verbose_name='ID')),
                ('rank', models.IntegerField(
                    default=0, help_text='Rank of the instance')),
                ('app', models.ForeignKey(help_text='Public apps',
                 on_delete=django.db.models.deletion.DO_NOTHING, to='apps.app')),
                ('categories', models.ManyToManyField(blank=True, default=None,
                 help_text='Categories of the app template', to='apps.apptemplatecategory')),
            ],
        ),
        migrations.AddField(
            model_name='app',
            name='run_graph',
            field=models.ManyToManyField(
                help_text='Run graph of the app', to='apps.apprungraphentry'),
        ),
        migrations.AddField(
            model_name='app',
            name='template',
            field=models.ForeignKey(blank=True, default=None, help_text='Template used for this app',
                                    null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='apps.apptemplate'),
        ),
        migrations.AddField(
            model_name='app',
            name='type',
            field=models.ForeignKey(
                help_text='Type of the app', on_delete=django.db.models.deletion.DO_NOTHING, to='apps.apptype'),
        ),
    ]
